package main

import "fmt"

func main() {
	s := "race car"
	fmt.Println(reverseVowels(s))
}

//#link: https://leetcode-cn.com/problems/reverse-vowels-of-a-string/
func reverseVowels(s string) string {
	sByte := []byte(s)
	for begin, end := 0, len(sByte)-1; begin < end; begin++ {
		if isContain(sByte[begin]) {
			for end > begin {
				if isContain(sByte[end]) {
					sByte[begin], sByte[end] = sByte[end], sByte[begin]
					end--
					break
				} else {
					end--
				}
			}
		}
	}

	return string(sByte)
}

/**
 * @Description: 是否包含
 */
func isContain(a byte) bool {
	vowels := []byte{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}
	for _, vowel := range vowels {
		if vowel == a {
			return true
		}
	}
	return false
}
